package com.ftg.learn.util;

import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

/**
 * @author 布衣
 */
@Data
@Schema(name = "分页对象")
public class PageEx<E> {

    @Schema(description = "当前页码")
    private Integer pageNum;
    @Schema(description = "每页数量")
    private Integer pageSize;
    @Schema(description = "总记录数")
    private Long total;
    @Schema(description = "总页数")
    private Integer totalPage;
    @Schema(description = "数据")
    private List<E> rows;

    public static <E> PageEx<E> convertToPageEx(PageInfo<E> pageInfo) {
        PageEx<E> p = new PageEx<E>();
        p.setPageNum(pageInfo.getPageNum());
        p.setPageSize(pageInfo.getPageSize());
        p.setTotal(pageInfo.getTotal());
        p.setTotalPage(pageInfo.getPages());
        p.setRows(pageInfo.getList());
        return p;
    }

}
